<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>【Git】6、将dev分支覆盖master分支 | 亦人亦码</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="在开发的过程中，本来在dev分支下开发，但是在此期间又对master分支修改，导致在将dev分支合并至master分支时，合并失败。从而考虑将dev分支覆盖master分支并设置为默认分支。">
<meta property="og:type" content="article">
<meta property="og:title" content="【Git】6、将dev分支覆盖master分支">
<meta property="og:url" content="https://xlh_blog.gitee.io/2023/04/06/%E3%80%90Git%E3%80%916%E3%80%81%E5%B0%86dev%E5%88%86%E6%94%AF%E8%A6%86%E7%9B%96master%E5%88%86%E6%94%AF/index.html">
<meta property="og:site_name" content="亦人亦码">
<meta property="og:description" content="在开发的过程中，本来在dev分支下开发，但是在此期间又对master分支修改，导致在将dev分支合并至master分支时，合并失败。从而考虑将dev分支覆盖master分支并设置为默认分支。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://xlh_blog.gitee.io/2023/04/06/%E3%80%90Git%E3%80%916%E3%80%81%E5%B0%86dev%E5%88%86%E6%94%AF%E8%A6%86%E7%9B%96master%E5%88%86%E6%94%AF/img1.jpg">
<meta property="og:image" content="https://xlh_blog.gitee.io/2023/04/06/%E3%80%90Git%E3%80%916%E3%80%81%E5%B0%86dev%E5%88%86%E6%94%AF%E8%A6%86%E7%9B%96master%E5%88%86%E6%94%AF/img2.jpg">
<meta property="article:published_time" content="2023-04-06T07:03:38.000Z">
<meta property="article:modified_time" content="2023-04-06T07:44:34.575Z">
<meta property="article:author" content="Mr.xi">
<meta property="article:tag" content="Java, PHP,Linux,博客">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://xlh_blog.gitee.io/2023/04/06/%E3%80%90Git%E3%80%916%E3%80%81%E5%B0%86dev%E5%88%86%E6%94%AF%E8%A6%86%E7%9B%96master%E5%88%86%E6%94%AF/img1.jpg">
  
    <link rel="alternate" href="/atom.xml" title="亦人亦码" type="application/atom+xml">
  
  
    <link rel="icon" href="/image/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">


<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">亦人亦码</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
          <a class="main-nav-link" href="/about">About</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://xlh_blog.gitee.io"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-【Git】6、将dev分支覆盖master分支" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2023/04/06/%E3%80%90Git%E3%80%916%E3%80%81%E5%B0%86dev%E5%88%86%E6%94%AF%E8%A6%86%E7%9B%96master%E5%88%86%E6%94%AF/" class="article-date">
  <time datetime="2023-04-06T07:03:38.000Z" itemprop="datePublished">2023-04-06</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Git/">Git</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      【Git】6、将dev分支覆盖master分支
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>在开发的过程中，本来在dev分支下开发，但是在此期间又对master分支修改，导致在将dev分支合并至master分支时，合并失败。从而考虑将dev分支覆盖master分支并设置为默认分支。</p>
<span id="more"></span>

<p>git仓库：gitlab</p>
<p>1、首先在gitlab中将master分支的保护取消</p>
<img src="/2023/04/06/%E3%80%90Git%E3%80%916%E3%80%81%E5%B0%86dev%E5%88%86%E6%94%AF%E8%A6%86%E7%9B%96master%E5%88%86%E6%94%AF/img1.jpg" class="">

<p>2、备份master分支</p>
<p>可以通过<code>git branch -m master master-bak</code>备份分支。或者在gitlab管理界面创建master分支</p>
<p>3、在gitlab操作界面将默认分支设置为dev分支</p>
<img src="/2023/04/06/%E3%80%90Git%E3%80%916%E3%80%81%E5%B0%86dev%E5%88%86%E6%94%AF%E8%A6%86%E7%9B%96master%E5%88%86%E6%94%AF/img2.jpg" class="">

<p>4、切换到dev分支下，删除master分支</p>
<p>删除本地分支：<code>git branch -D master</code></p>
<p>删除远程分支：<code>git push origin :master</code></p>
<p>5、创建master分支，基于当前的dev分支创建master分支</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -b master</span><br></pre></td></tr></table></figure>

<p>6、将本地的master分支推送到远程仓库</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push origin master:master</span><br></pre></td></tr></table></figure>

<p>7、重新将默认分支设置为master分支，并重新开启分支保护</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://xlh_blog.gitee.io/2023/04/06/%E3%80%90Git%E3%80%916%E3%80%81%E5%B0%86dev%E5%88%86%E6%94%AF%E8%A6%86%E7%9B%96master%E5%88%86%E6%94%AF/" data-id="clt2kwbin000ls33725p03vs2" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2023/04/06/%E3%80%90%E5%90%8E%E7%AB%AF%E3%80%91SpringBoot%E6%95%B4%E5%90%88MQTT%EF%BC%88EMQX%EF%BC%89/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          【后端】SpringBoot整合MQTT（EMQX）
        
      </div>
    </a>
  
  
    <a href="/2023/04/06/%E3%80%90Git%E3%80%915%E3%80%81Git-SVN%E7%AE%A1%E7%90%86%E5%90%8C%E4%B8%80%E4%B8%AA%E9%A1%B9%E7%9B%AE/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">【Git】5、Git+SVN管理同一个项目</div>
    </a>
  
</nav>

  
</article>




</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Activiti7/">Activiti7</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Git/">Git</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%85%B6%E4%BB%96/">其他</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%90%8E%E7%AB%AF/">后端</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%BF%90%E7%BB%B4/">运维</a></li></ul>
    </div>
  </div>


  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/04/">四月 2023</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2023/04/10/%E3%80%90%E5%85%B6%E4%BB%96%E3%80%911%E3%80%81Mac%E9%83%A8%E7%BD%B2LskyPro%E6%90%AD%E5%BB%BA%E6%9C%AC%E5%9C%B0%E5%9B%BE%E5%BA%8A/">【其他】1、Mac部署LskyPro搭建本地图床</a>
          </li>
        
          <li>
            <a href="/2023/04/06/%E3%80%90%E8%BF%90%E7%BB%B4%E3%80%917%E3%80%81%E8%A7%A3%E5%86%B3virtualBox%E5%AF%BC%E5%85%A5voa%E6%96%87%E4%BB%B6%E5%90%8E%E6%97%A0%E6%B3%95%E4%B8%8A%E7%BD%91%E9%97%AE%E9%A2%98/">【运维】7、解决virtualBox导入voa文件后无法上网问题</a>
          </li>
        
          <li>
            <a href="/2023/04/06/%E3%80%90%E8%BF%90%E7%BB%B4%E3%80%916%E3%80%81Docker%E8%BF%90%E8%A1%8CSpringCloud%E5%BE%AE%E6%9C%8D%E5%8A%A1%E5%B9%B6%E9%80%9A%E8%BF%87IP%E8%BF%9B%E8%A1%8C%E6%9C%8D%E5%8A%A1%E6%B3%A8%E5%86%8C/">【运维】5、Docker运行SpringCloud微服务并通过IP进行服务注册</a>
          </li>
        
          <li>
            <a href="/2023/04/06/%E3%80%90%E8%BF%90%E7%BB%B4%E3%80%915%E3%80%81win10%E9%80%9A%E8%BF%87vagrant-virtulbox%E6%90%AD%E5%BB%BAcentos7%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%8E%AF%E5%A2%83%E6%97%B6%E6%8A%A5%E9%94%99/">【运维】5、win10通过vagrant+virtulbox搭建centos7虚拟机环境时报错</a>
          </li>
        
          <li>
            <a href="/2023/04/06/%E3%80%90%E5%90%8E%E7%AB%AF%E3%80%91SpringBoot%E6%95%B4%E5%90%88MQTT%EF%BC%88EMQX%EF%BC%89/">【后端】SpringBoot整合MQTT（EMQX）</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2024 Mr.xi<br>
        <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
        <span id="busuanzi_container_site_pv">
          本文总阅读量<span id="busuanzi_value_page_pv"></span>次
        </span><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备18049089号-2</a>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>


</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>





<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?803c71743b7cfc4dac421ac4fc646963";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



  </div>
</body>
</html>